package edu.ccut.saturn.studio.export.excel;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;

/**
 * 
 * @author 杨艳斌
 * 
 * @version 1.1 2009.12.17
 */

public class ExportReportWizard extends Wizard implements IExportWizard{
	
	private ExportReportWizardpage page;
	private ISelection selection;
	private List<HSSFSheet> clonesheets = new ArrayList<HSSFSheet>();					//复制的sheet页的集合

	public void addPages() {															//添加向导页
		page = new ExportReportWizardpage(selection);
		addPage(page);
	}
	
	public boolean performFinish(){													//点击finish按钮所触发的事件
		try {
		
			List<IProject> projects = page.getProjects();
			
			if (!new File(page.getSaveDirectory()).exists()) {
				(new File(page.getSaveDirectory())).mkdir();
			}
			
			for (IProject project : projects) {
				AnalyseModel.generateProjectSum(project, 
						page.getSaveDirectory(), projects.size(), clonesheets);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return true;
	}

	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.selection = selection;
	}
}
